package com.booter.gateway.filter;

//@Component
//public class ReadMultipartBodyFilter implements GlobalFilter, Ordered {
//    private final static Logger logger = LoggerFactory.getLogger(ReadMultipartBodyFilter.class);
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        return exchange.getRequest().getBody().collectList().flatMap(dataBuffers -> {
//            byte[] totalBytes = dataBuffers.stream().map(dataBuffer -> {
//                try {
//                    byte[] bytes = IOUtils.toByteArray(dataBuffer.asInputStream());
//                    logger.info(new String(bytes));
//                    return bytes;
//                } catch (IOException e) {
//                    throw new RuntimeException(e);
//                }
//            }).reduce(this::addBytes).get();
//            ServerHttpRequestDecorator decorator = new ServerHttpRequestDecorator(exchange.getRequest()) {
//                @Override
//                public Flux<DataBuffer> getBody() {
//                    return Flux.just(buffer(totalBytes));
//                }
//            };
//            Mono<MultiValueMap<String, Part>> multiValueMapMono = repackageMultipartData(decorator, codecConfigurer);
//            return multiValueMapMono.flatMap(part -> {
//                System.out.println(((FormFieldPart) part.getFirst("param")).value());
//                return chain.filter(exchange.mutate().request(decorator).build());
//            });
//        });
//
//    }
//
//
//    @Override
//    public int getOrder() {
//        return Ordered.HIGHEST_PRECEDENCE;
//    }
//
//}